public class LinkedList {
    private Node Head = null;
    private Node Tail = null;
    private Node Pointer = null;
    private int Length = 0;


    //在当前结点前插入一个结点，并使其成为当前结点
    public void insert(Object d) {
        Node e = new Node(d, null);
        if (Length == 0) {
            Tail = e;
            Head = e;
        } else {
            Node temp = cursor();
            e.next = temp;
            if (Pointer == null) {
                Head = e;
            } else
                Pointer.next = e;
        }
        Length++;
    }

    //将当前结点移出链表，下一个结点成为当前结点，如果移出的结点是最后一个结点，则第一个结点成为当前结点
    public Object remove() {
        Object temp;
        if (Length == 0)
            return 0;
        else if (Length == 1) {
            temp = Head.data;
            deleteAll();
        } else {
            Node cur = cursor();
            temp = cur.data;
            if (cur == Head)
                Head = cur.next;
            else if (cur == Tail) {
                Pointer.next = null;
                Tail = Pointer;
                reset();
            } else
                Pointer.next = cur.next;
            Length--;
        }
        return temp;
    }


    //返回当前结点的指针
    private Node cursor() {
        if (Head == null)
            return null;
        else if (Pointer == null)
            return Head;
        else
            return Pointer.next;


    }

    //返回当前结点的值
    public Object currentNode() {
        Node temp = cursor();
        return temp.data;
    }

    public void deleteAll() {
        Head = null;
        Tail = null;
        Pointer = null;
        Length = 0;
    }

    public void reset() {
        Pointer = null;

    }


//链表实现

    public void list1() {
        int s = 0;
        LinkedList a = new LinkedList();
        for (int i = 1; i <= 10; i++) {
            if (a.Length == 9) {
                s = 1;
                while (a.Length != 0) {
                    s = s * 2 + 2;
                    a.remove();
                }
                System.out.println("链表实现:");
                System.out.println("桃子总数:" + s);
            } else a.insert(new Integer(i));

        }

    }
}
